
class_name CRanks

extends EventDispatcher

signal UUID_changed(old_value, new_value) 
signal CharName_changed(old_value, new_value) 
signal CharID_changed(old_value, new_value) 
signal BaseData1_changed(old_value, new_value) 
signal BaseData2_changed(old_value, new_value) 
signal RankType_changed(old_value, new_value) 
signal RankIndex_changed(old_value, new_value) 
signal Key1_changed(old_value, new_value) 
signal Key2_changed(old_value, new_value) 
signal Key3_changed(old_value, new_value) 
signal Key4_changed(old_value, new_value) 
signal Key5_changed(old_value, new_value) 
signal Key6_changed(old_value, new_value) 


var m_tblAlias
var bInited = false
func _init(_uuid)->void:
    self.UUID = _uuid
    self.CharName = ''
    self.CharID = 0
    self.BaseData1 = 0
    self.BaseData2 = 0
    self.RankType = 0
    self.RankIndex = 0
    self.Key1 = 0
    self.Key2 = 0
    self.Key3 = 0
    self.Key4 = 0
    self.Key5 = 0
    self.Key6 = 0

    self.m_tblAlias = {
 
    }

func UnPack(_bufferStream):
    self.UUID = _bufferStream.ReadInt64()
    self.CharName = _bufferStream.ReadString(TableCommonDefine.ECharLen.eCL_CharName)
    self.CharID = _bufferStream.ReadInt64()
    self.BaseData1 = _bufferStream.ReadInt64()
    self.BaseData2 = _bufferStream.ReadInt64()
    self.RankType = _bufferStream.ReadInt32()
    self.RankIndex = _bufferStream.ReadInt32()
    self.Key1 = _bufferStream.ReadUint64()
    self.Key2 = _bufferStream.ReadUint64()
    self.Key3 = _bufferStream.ReadUint64()
    self.Key4 = _bufferStream.ReadUint64()
    self.Key5 = _bufferStream.ReadUint64()
    self.Key6 = _bufferStream.ReadUint64()

    self.bInited = true


func GetTableName():
    return 'Ranks'

func CopyFrom(other):
    self.CharName = other.CharName
    self.CharID = other.CharID
    self.BaseData1 = other.BaseData1
    self.BaseData2 = other.BaseData2
    self.RankType = other.RankType
    self.RankIndex = other.RankIndex
    self.Key1 = other.Key1
    self.Key2 = other.Key2
    self.Key3 = other.Key3
    self.Key4 = other.Key4
    self.Key5 = other.Key5
    self.Key6 = other.Key6


func OnDataChanged( fieldName, oldValue, newValue):
    if oldValue == newValue:
        return
    
    self.DispatchEvent(fieldName, [self, oldValue, newValue])
    #  Alias
    if self.m_tblAlias[fieldName] != null:
        for i in range(self.m_tblAlias[fieldName].size()):
            self.DispatchEvent(self.m_tblAlias[fieldName][i], [self, oldValue, newValue])

func UnPackField(_fieldId, _bufferStream, _varLen ):
    if _fieldId < 0 or _fieldId == 0xffff:
        var old = CRanks.new(self.m_UUID)
        old.CopyFrom( self )
        self.UnPack( _bufferStream )
        self.DispatchEvent("CRanks", [self, old, self])
        return true

    print("UnPackField error tblName = Ranks, className = CRanks, _fieldId = ", _fieldId)
    # if _fieldId > Fields_RanksID.size():
    #     var szLog = 'CRanks.UnPackField  _fieldId(%d) < 0 or _fieldId(%d) > #Fields_RanksID(%d)' % [_fieldId, _fieldId,  Fields_RanksID.size()]
    #     print(szLog)
    #     return false

    # Fields_RanksID[_fieldId].reader( self, _bufferStream, _varLen)

    return true

func AddField(_fieldId, _bufferStream):
    print( "[TABLEDATA] error AddField", "CRanks", _fieldId )

    
func DelField(_fieldId ):
    print( "[TABLEDATA] error DelField", "CRanks", _fieldId )

var UUID:
    set(value):
        var old = self.m_UUID
        self.UUID = _value
        self.UUID_changed.emit(old, _value)

    get:
        return self.UUID


var CharName:
    set(value):
        var old = self.m_CharName
        self.CharName = _value
        self.CharName_changed.emit(old, _value)

    get:
        return self.CharName


var CharID:
    set(value):
        var old = self.m_CharID
        self.CharID = _value
        self.CharID_changed.emit(old, _value)

    get:
        return self.CharID


var BaseData1:
    set(value):
        var old = self.m_BaseData1
        self.BaseData1 = _value
        self.BaseData1_changed.emit(old, _value)

    get:
        return self.BaseData1


var BaseData2:
    set(value):
        var old = self.m_BaseData2
        self.BaseData2 = _value
        self.BaseData2_changed.emit(old, _value)

    get:
        return self.BaseData2


var RankType:
    set(value):
        var old = self.m_RankType
        self.RankType = _value
        self.RankType_changed.emit(old, _value)

    get:
        return self.RankType


var RankIndex:
    set(value):
        var old = self.m_RankIndex
        self.RankIndex = _value
        self.RankIndex_changed.emit(old, _value)

    get:
        return self.RankIndex


var Key1:
    set(value):
        var old = self.m_Key1
        self.Key1 = _value
        self.Key1_changed.emit(old, _value)

    get:
        return self.Key1


var Key2:
    set(value):
        var old = self.m_Key2
        self.Key2 = _value
        self.Key2_changed.emit(old, _value)

    get:
        return self.Key2


var Key3:
    set(value):
        var old = self.m_Key3
        self.Key3 = _value
        self.Key3_changed.emit(old, _value)

    get:
        return self.Key3


var Key4:
    set(value):
        var old = self.m_Key4
        self.Key4 = _value
        self.Key4_changed.emit(old, _value)

    get:
        return self.Key4


var Key5:
    set(value):
        var old = self.m_Key5
        self.Key5 = _value
        self.Key5_changed.emit(old, _value)

    get:
        return self.Key5


var Key6:
    set(value):
        var old = self.m_Key6
        self.Key6 = _value
        self.Key6_changed.emit(old, _value)

    get:
        return self.Key6



